package com.butterfly.web.components;

import org.apache.commons.lang3.StringUtils;
import org.apache.tapestry5.SymbolConstants;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.ioc.annotations.Inject;
import org.apache.tapestry5.ioc.annotations.Symbol;
import org.apache.tapestry5.services.Request;
import org.springframework.security.core.context.SecurityContextHolder;

public class TopNavBar {
	
	@Inject
	private Request request;
	@Inject
	@Symbol(SymbolConstants.EXECUTION_MODE)
	private String executionMode;
	
	@Property
	private String environment;
	
	void setupRender() {
		if(StringUtils.equals("development", executionMode)) {
			environment = "DEV";
		} else if(StringUtils.equals("qa", executionMode)) {
			environment = "QA";
		} else if(StringUtils.equals(SymbolConstants.PRODUCTION_MODE, executionMode)) { 
			environment = "";
		}
	}
	
	public String getEnvironmentClass() {
		if(StringUtils.equals("DEV", environment)) {
			return "label label-info";
		} else if(StringUtils.equals("QA", environment)) {
			return "label label-warning";
		}
		
		return "";
	}
	
	public String getUsername() {
		return SecurityContextHolder.getContext().getAuthentication().getName();
	}
	
	public String getContextPath() {
		return request.getContextPath();
	}		
}
